<%@ page language="java" contentType="text/html; charset=utf-8"
		 pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
	<title>重置密码</title>
	<meta charset="utf-8"/>
	<link rel="stylesheet" href="../css/bootstrap.css"/>
	<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../easyui/demo/demo.css">
	<script type="text/javascript" src="../easyui/jquery.min.js"></script>
	<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../js/sha1.js"></script>
</head>
<body>
<div class="container-fluid">

	<jsp:include page="../admin/header.jsp"></jsp:include>

	<br><br>

	<form class="form-horizontal" action="" method="post">
		<input type="hidden" name="id" id="id" value="${u.id }">
		<input type="hidden" name="userName" id="userName" value="${u.userName }">
		<div class="form-group">
			<label for="input_name" class="col-sm-1 control-label">用户名</label>
			<div class="col-sm-5">${u.userName }</div>
		</div>
		<div class="form-group">
			<label for="input_name" class="col-sm-1 control-label">邮箱</label>
			<div class="col-sm-5">${u.email }</div>
		</div>
		<div class="form-group">
			<label for="input_name" class="col-sm-1 control-label">新密码</label>
			<div class="col-sm-6">
				<input type="password" class="form-control" id="password" name="password" value="" required="required">
			</div>
		</div>
		<div class="form-group">
			<label for="input_name" class="col-sm-1 control-label">确认新密码</label>
			<div class="col-sm-6">
				<input type="password" class="form-control" id="confirmPassword" name="confirmPassword" value="" required="required">
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-offset-1 col-sm-10">
				<button type="button" class="btn btn-success" onclick="changePasswordUser()">提交修改</button>
			</div>
		</div>
	</form>

	<span style="color:red;"></span>

</div>
</body>
<script type="text/javascript">
function isBlank(val){
    if (val == undefined|| val == null || val == "") return true;
    else return false;
}

function changePasswordUser(){
    var userName = $("#userName").val();
    var password = $("#password").val();
    var confirmPassword = $("#confirmPassword").val();
    if (isBlank(password)||isBlank(confirmPassword)){
        $.messager.alert("错误","新密码不可为空！","error");
        return;
    }
    if (password!=confirmPassword){
        $.messager.alert("错误","新密码不匹配！","error");
        return;
    }
    $.ajax({
        type: "post",
        url: "../userController/changePasswordUser",
        data:  {
            userName:userName,
            password:hex_sha1(password),
        },
        dataType: 'json',
        success: function(data, textStatus) {
            if (data.success) {
            	window.location="../admin/user_list";
            }
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}
</script>
</html>